Analysis of EECA’s Energy End Use Data for New Zealand.
dataFile <- path.expand("~/Dropbox/data/EECA/eeud_data-2024-08-16-657.csv")
dt <- data.table::fread(dataFile)
The data gives total energy used (TJ) per year for different purposes by different sectors and by type.
For example, Figure 2.1 shows total energy use over time by sector group while Figure 2.2 shows the total by energy (fuel) type.
make_colPlot <- function(dt, xVar, yVar, fillVar, scaleVar){
p <- ggplot2::ggplot(dt, aes(x = get(xVar),
y = get(yVar),
fill = get(fillVar))) +
geom_col() +
scale_fill_discrete(name = scaleVar)
return(p)
}
plotDT <- dt[, .(Total_TJ = sum(TJ,na.rm = TRUE)),
keyby = .(SectorGroup, Period)]
make_colPlot(plotDT, "Period", "Total_TJ", "SectorGroup", "Sector") +
labs(x = "Year", y = "Total TJ")
Figure 2.1: Energy use by sector over time
message("2022 total")
## 2022 total
sum(plotDT[Period == 2022, Total_TJ])
## [1] 541085.4
plotDT <- dt[, .(Total_TJ = sum(TJ, na.rm = TRUE)),
keyby = .(FuelGroup, Period)]
make_colPlot(plotDT, "Period", "Total_TJ", "FuelGroup", "FuelGroup") +
labs(x = "Year", y = "Total TJ")
Figure 2.2: Energy use by fuel group over time
message("2022 total")
## 2022 total
sum(plotDT[Period == 2022, Total_TJ])
## [1] 541085.4
plotDT <- dt[Fuel %like% "Electricity", .(Total_TJ = sum(TJ, na.rm = TRUE)),
keyby = .(SectorGroup, Period)]
make_colPlot(plotDT, "Period", "Total_TJ", "SectorGroup", "SectorGroup") +
labs(x = "Year", y = "Total TJ")
Figure 2.3: Electricity use by sector over time
message("2022 total electricity")
## 2022 total electricity
sum(plotDT[Period == 2022, Total_TJ])
## [1] 138548.1
ggplot2::ggplot(dt[Fuel %like% "Electricity" &
Sector %like% "Residential"],
aes(x = Period, y = TJ, fill = EndUseGroup)) +
geom_col(position = "stack")
elec_tj <- dt[Fuel %like% "Electricity"]
elec_tj[, TJ_pc := 100 * TJ/sum(TJ, na.rm = TRUE), keyby = .(Period)]
resElec_2022_pc <- sum(elec_tj[Period == 2022 &
Sector %like% "Residential", TJ_pc])
resElec_2022 <- sum(elec_tj[Period == 2022 &
Sector %like% "Residential", TJ])
resElec_2022_spaceHeat <- sum(elec_tj[Period == 2022 &
Sector %like% "Residential" &
EndUse %like% "Space Heating", TJ])
resElec_2022_spaceHeat_pc <- sum(elec_tj[Period == 2022 &
Sector %like% "Residential" &
EndUse %like% "Space Heating", TJ_pc])
p <- ggplot2::ggplot(dt[Fuel %like% "Electricity" &
Sector %like% "Residential" &
EndUse %like% "Heat"],
aes(x = Period, y = TJ,
fill = Technology
)) +
geom_col(position = "stack") +
theme(legend.position = "bottom")
plotly::ggplotly(p)
Figure 3.1: Electricity used for heat
2022
ggplot2::ggplot(elec_tj[Sector %like% "Residential" &
EndUse %like% "Space Heat"], aes(x = Period,
y = TJ,
colour = Technology))+
geom_line()
# theme(legend.position = "bottom") +
# guides(colour=guide_legend(ncol=1))
ggplot2::ggplot(elec_tj[Sector %like% "Residential" &
EndUse %like% "Space Heat"], aes(x = Period,
y = TJ_pc,
colour = Technology))+
geom_line() +
labs(y = "% total electricity")